﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARR.Entities.Common;
using ARR.Entities.ComponentModel;
using ARR.Shared;

namespace ARR.Entities.Validation.Common
{
    [Serializable]
    public class EMailAddress : ValidationBase
    {
        private string emailRegex = @"^(?("""")("""".+?""""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$";

        public EMailAddress(string propertyName) : base(propertyName, null)
        {            
            base.ErrorMessage = Errors.EmailAddressNotValid;
        }

        public override bool Validate(ValidatableEntity entity)
        {
            return new RegexValidation(base.PropertyName, base.ErrorMessage, emailRegex).Validate(entity);
        }
    }
}
